package com.yulan.dp;

import org.junit.Test;

/**
 * 面试题46. 把数字翻译成字符串
 */
public class LeetCode_46 {
    public int translateNum(int num){
        String str = String.valueOf(num);
        int[] dp = new int[str.length()+1];
        int a = 1,b = 1;
        for(int i = 2;i<=str.length();i++){
            String tmp = str.substring(i-2,i);
            int c = tmp.compareTo("10") >=0 && tmp.compareTo("25")<=0 ? a+b : a;
            System.out.println(c);
            b = a;
            a = c;
        }
        return a;
    }

    public int re_translateNum(int n){
        if(n<10) return 1;
        return (n%100 < 10 || n%100 > 25) ? re_translateNum(n/10) : re_translateNum(n/10) + translateNum(n/100);
    }

    @Test
    public void test(){
        System.out.println(translateNum(12258));
    }
}
